package cn.itcast.mq.config;

import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.FanoutExchange;
import org.springframework.amqp.core.Queue;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class SpringAmqpConf {
    /*
    交换机
     */
    @Bean
    public FanoutExchange fanoutExchange(){
        return new FanoutExchange("zhang.fanout");
    }

    /*
    队列1
     */
    @Bean
    public Queue fanoutqueue1(){
       return new Queue("fanout.queue1");
    }

    /*
    把队列1绑定到交换机
     */
    @Bean
    public Binding bindingQueue1(Queue fanoutqueue1,FanoutExchange fanoutExchange){
        return BindingBuilder.bind(fanoutqueue1).to(fanoutExchange);
    }

    /*
    队列2
     */
    @Bean
    public Queue fanoutqueue2(){
        return new Queue("fanout.queue2");
    }


    /*
    把队列1绑定到交换机
     */
    @Bean
    public Binding bindingQueue2(Queue fanoutqueue2,FanoutExchange fanoutExchange){
        return BindingBuilder.bind(fanoutqueue2).to(fanoutExchange);
    }
}
